<template>
    <div class="exportExcel" style="display: none">
        <excel-export :filename="exportExcel.filename" :sheet="exportExcel.sheet" :manual="true" :on-error="onExportExcelError"
                      ref="excelExport">
        </excel-export>
    </div>
</template>

<script>
import { ExcelExport } from 'pikaz-excel-js';
export default {
    name: "exportExcel",
    data() {
        return {
            loading: null,
            exportExcel: {
                bookType: 'xls',
                filename: '',
                sheet: []
            }
        }
    },
    methods: {
        exports(fileName, dataList = []) {
            var date = new Date();
            this.exportExcel.filename = fileName;
            this.exportExcel.sheet = [];
            for (var i = 0; i < dataList.length; i++) {
                dataList[i].globalStyle = { alignment: { horizontal: "left" } };
                dataList[i].colWidth = new Array(dataList[i].keys.length).fill('20');
                this.exportExcel.sheet.push(dataList[i]);
            }
            console.log(this.exportExcel)
            this.exportExcel.filename = fileName + date.getFullYear() + "" + date.getMonth() + 1 + "" + date.getDate() + "" + date.getHours() + "" + date.getMinutes();
            this.$refs.excelExport.pikaExportExcel();
        },
        showLoading() {
            this.loading = this.$loading({
                lock: true,
                text: "正在导出",
                spinner: "el-icon-loading",
                background: "rgba(0, 0, 0, 0.7)",
            });
        },
        closeLoading() {
            this.loading.close();
        },
        onExportExcelError() {
            this.$emit("exportExcelError");
        }
    },
    components: {
        ExcelExport
    }
}
</script>